package com.train.mgr.modules.biz.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.train.common.utils.AuthUtils;
import com.train.mgr.modules.biz.entity.CourseUser;
import com.train.mgr.modules.biz.entity.LessonUserStudy;
import com.train.mgr.modules.biz.mapper.LessonUserStudyMapper;
import com.train.mgr.modules.biz.service.ILessonUserStudyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * <p>
 * 用户课时学习表 服务实现类
 * </p>
 *
 * @author cxg
 * @date 2025-09-30
 */
@Slf4j
@RequiredArgsConstructor
@Service("ILessonUserStudyService")
public class LessonUserStudyServiceImpl extends ServiceImpl<LessonUserStudyMapper, LessonUserStudy> implements ILessonUserStudyService {


    @Override
    public List<LessonUserStudy> findListByCourseId(Long customerId,List<Long> lessonIds,Long courseId,Long userId){
        LambdaQueryWrapper<LessonUserStudy> queryStudyWrapper = new LambdaQueryWrapper<LessonUserStudy>();
        queryStudyWrapper.eq(LessonUserStudy::getCustomerId,customerId);
        queryStudyWrapper.eq(LessonUserStudy::getCourseId,courseId);
        queryStudyWrapper.in(CollUtil.isNotEmpty(lessonIds),LessonUserStudy::getLessonId,lessonIds);
        queryStudyWrapper.eq(LessonUserStudy::getUserId,userId);
        queryStudyWrapper.eq(LessonUserStudy::getIsDeleted,0);
        return baseMapper.selectList(queryStudyWrapper);
    }

    @Override
    public List<LessonUserStudy> getUserStudyList(Long courseId,Long lessonId) {
        return baseMapper.getUserStudyList(courseId,lessonId, AuthUtils.getCurrentUser().getId());
    }


}
